package cn.lcsjsxy.yxc.exercise.java050529;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

import static cn.lcsjsxy.yxc.exercise.java050529.StudentGradeAnalyzer.addStudent;

public class StudentGradeApplication {
    public static void main(String[] args) {
        Map<String, List<Double>> map = new HashMap<>();
        Scanner scanner = new Scanner(System.in);
        boolean isFlag = true;

        while (isFlag) {
            System.out.println("\n1.添加学生");
            System.out.println("2.计算平均分");
            System.out.println("3.平均最高分");
            System.out.println("4.不及格学生");
            System.out.println("5.排名");
            System.out.println("6.退出");
            System.out.print("请输入：");

            // 验证输入是否为整数
            if (!scanner.hasNextInt()) {
                System.out.println("错误：请输入数字选项！");
                scanner.next(); // 清除无效输入
                continue;
            }

            int choice = scanner.nextInt();
            scanner.nextLine(); //消耗掉输入流中的换行符！坑死我了Scanner！

            switch (choice) {
                case 1:
                    addStudent(map);
                    break;
                case 2:
                    System.out.println(StudentGradeAnalyzer.averageScore(map));
                    break;
                case 3:
                    System.out.println(StudentGradeAnalyzer.averageMaxStudent(map));
                    break;
                case 4:
                    System.out.println(StudentGradeAnalyzer.failStudent(map));
                    break;
                case 5:
                    StudentGradeAnalyzer.printStudentScore(map);
                    break;
                case 6:
                    isFlag = false;
                    System.out.println("退出程序！");
                    break;
                default:
                    System.out.println("无效选项，请重新输入！");
            }
        }
        scanner.close();
    }
}

